home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0231_Re: StretchBlt with D2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  1.2 KB  |  42 lines

  1. {
  2. Here is some code I use to print a bitmap with StretchDIBits.  The
  3. function accomplishes the same thing as StretchBlt.  The difference is
  4. that it operates with Device Independent Bitmaps (DIBs).  If you want to
  5. use
  6. StretchBlt, you would use it like this:
  7. }
  8.  
  9. StretchBlt(DestinationRectangle.Handle, DestX, DestY, DestWidth,
  10.               DestH, Bitmap.Handle,SourceX, SourceY, SourceWidth,
  11.               SourceHeight, SRCCOPY);
  12.  
  13. { ----- begin code ----- }
  14. procedure TfrmMain.PrintBitmap(Bitmap: TBitmap; X, Y, W, H: Integer);
  15.   var
  16.     Info: PBitmapInfo;
  17.     InfoSize: Integer;
  18.     Image: Pointer;
  19.     ImageSize: Longint;
  20.   begin
  21.     with Bitmap do
  22.     begin
  23.       GetDIBSizes(Handle, InfoSize, ImageSize);
  24.       Info := MemAlloc(InfoSize);
  25.       try
  26.         Image := MemAlloc(ImageSize);
  27.         try
  28.           GetDIB(Handle, Palette, Info^, Image^);
  29.           with Info^.bmiHeader do
  30.             StretchDIBits(Printer.Canvas.Handle, X, Y, W,H,
  31.                                 0, 0, biWidth,biHeight,Image,Info^,
  32.                                 DIB_RGB_COLORS,SRCCOPY);
  33.         finally
  34.           FreeMem(Image, ImageSize);
  35.         end;
  36.       finally
  37.         FreeMem(Info, InfoSize);
  38.       end;
  39.     end;
  40.   end;
  41. { ----- end code ----- }
  42.